﻿using Net.Client;
using Wordgames;

namespace WordGames.System
{
    public class TcpNetwork : TcpClientUnit
    {
        public string Local { get; internal set; }
        public string Remote { get; internal set; }
        public string Route { get; internal set; }
        public UserData User { get; internal set; }

        public void Init()
        {
            OnRpcInvoke = (model) =>
            {
                if (model.Token > 0)
                {
                    RpcAdapter.Enqueue(this, model);
                    return;
                }
                var services = ClusterSystem.Services;
                for (int i = 0; i < services.Count; i++)
                {
                    if (services[i].HostName == Local)
                        services[i].OnMessageHandler(this, model);
                }
            };
        }

        public override string ToString()
        {
            return $"用户ID:{UserId} Route:{Route}";
        }
    }
}
